package com.tjsinfo.tjsoa.reminded.action;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.DayFormat;
import com.tjsinfo.tjsoa.reminded.vo.TSystemReminded;
import com.tjsinfo.tjsoa.reminded.bo.TSystemRemindedManager;
import com.tjsinfo.tjsoa.system.dao.ITSystemDepartmentDao;
import com.tjsinfo.tjsoa.system.vo.User;

public class RemindedSaveAction extends Action {
	TSystemRemindedManager systemRemindedManager;
	private ITSystemDepartmentDao departmentDao;
	
	public TSystemRemindedManager getSystemRemindedManager() {
		return systemRemindedManager;
	}

	public void setSystemRemindedManager(
			TSystemRemindedManager systemRemindedManager) {
		this.systemRemindedManager = systemRemindedManager;
	}
	
	public ITSystemDepartmentDao getDepartmentDao() {
		return departmentDao;
	}

	public void setDepartmentDao(ITSystemDepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			HttpSession session=request.getSession();
			User user=(User)session.getAttribute("user");
            Date createDate = DayFormat.getCurrentUtilDate();
			
			TSystemReminded tsf=new TSystemReminded();
			tsf.setUserId(user.getUser_id());
			tsf.setUserName(user.getUsername());
			String oname=user.getDepartment().substring(1, user.getDepartment().length()-1);
			tsf.setOrganizeName(departmentDao.findById(oname).getDeptName());
			tsf.setTitle(request.getParameter("title"));
			tsf.setContent(request.getParameter("content"));
			tsf.setCreateDate(createDate);
			String IdList = ","+request.getParameter("id_list");
			tsf.setIdList(IdList);
			String nameList = ","+request.getParameter("name_list");
			tsf.setNameList(nameList);
			tsf.setReadIdList(","+request.getParameter("id_list"));
			tsf.setReadNameList(",");
			tsf.setMemo(",");
//			TSystemRemindedManager tsfm=new TSystemRemindedManagerImpl();
			systemRemindedManager.save(tsf);
			
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();

			return mapping.findForward("failed");
		}
	}
}
